package com.heima.article.controller;

import com.heima.article.dto.ArticleDto;
import com.heima.article.dto.ArticleHomeDto;
import com.heima.article.dto.ArticleInfoDto;
import com.heima.article.service.IApArticleService;
import com.heima.common.dto.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 文章信息表，存储已发布的文章 前端控制器
 * </p>
 *
 * @author SpaceTraveller
 * @since 2022-11-07
 */
@RestController
@RequestMapping("/api/v1/article")
@Api(tags = "文章信息表，存储已发布的文章接口")
public class ApArticleController {

    @Autowired
    private IApArticleService apArticleService;

    /**
     * 保存文章信息
     * @param articleDto
     * @return
     */
    @PostMapping("/publishOrUpdate")
    @ApiOperation(value = "保存文章信息",notes = "author:SpaceTraveller")
    @ApiImplicitParam(name = "articleDto",value = "请求体对象",required = true,dataType = "ArticleDto")
    public Long publishOrUpdate(@RequestBody ArticleDto articleDto) {
        return apArticleService.publishOrUpdate(articleDto);
    }

    /**
     * 用户端加载文章列表,首次加载
     * @param dto
     * @return
     */
    @PostMapping("/load")
    @ApiOperation(value = "用户端加载文章列表",notes = "author:SpaceTraveller")
    @ApiImplicitParam(name = "dto",value = "请求体对象",required = true,dataType = "ArticleHomeDto")
    public ResponseResult load(@RequestBody ArticleHomeDto dto) {
        return apArticleService.load(dto,0);
    }
    /**
     * 用户端加载文章列表,最新
     * @param dto
     * @return
     */
    @PostMapping("/loadnew")
    @ApiOperation(value = "用户端加载文章列表",notes = "author:SpaceTraveller")
    @ApiImplicitParam(name = "dto",value = "请求体对象",required = true,dataType = "ArticleHomeDto")
    public ResponseResult loadNew(@RequestBody ArticleHomeDto dto) {
        return apArticleService.load(dto,1);
    }

    /**
     * 用户端加载文章列表,更多
     * @param dto
     * @return
     */
    @PostMapping("/loadmore")
    @ApiOperation(value = "用户端加载文章列表",notes = "author:SpaceTraveller")
    @ApiImplicitParam(name = "dto",value = "请求体对象",required = true,dataType = "ArticleHomeDto")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto dto) {
        return apArticleService.load(dto,2);
    }

    /**
     * 加载文章详情
     * @param dto
     * @return
     */
    @PostMapping("/load_article_info")
    @ApiOperation(value = "加载文章详情",notes = "author:SpaceTraveller")
    @ApiImplicitParam(name = "dto",value = "请求体对象",required = true,dataType = "ArticleInfoDto")
    public ResponseResult loadArticleInfo(@RequestBody ArticleInfoDto dto){
        return apArticleService.loadArticleInfo(dto);
    }

    /**
     * 加载文章详情
     * @param dto
     * @return
     */
    @PostMapping("/load_article_behavior")
    @ApiOperation(value = "加载文章详情",notes = "author:SpaceTraveller")
    @ApiImplicitParam(name = "dto",value = "请求体对象",required = true,dataType = "ArticleInfoDto")
    public ResponseResult loadArticleBehavior(@RequestBody ArticleInfoDto dto){
        return apArticleService.loadArticleBehavior(dto);
    }


}
